package cn.frank.framework.caesar.module.ai.qwen.conf.logback;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

/**
 * @description: TODO
 * @author: renjiangyang
 * @date 2024/4/22 9:40:38
 * @since 1.8
 */
@Data
public class AppenderMarkerFilter extends Filter<ILoggingEvent> {

    private String marker;

    /**
     * 使用举例：
     * log.error(AppenderMarkerFilter.alone, "转换失败\n原始地址：{}\n代理地址：{}", url, url2, e);
     */
    public static final Marker alone = MarkerFactory.getMarker("ALONE");

    @Override
    public FilterReply decide(ILoggingEvent event) {
        if (StrUtil.equals(marker, event.getMarker().toString())) {
            return FilterReply.ACCEPT;
        } else {
            return FilterReply.DENY;
        }
    }
}